﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace VNPT.DoiSoat.DoiSoat
{
    public partial class fEditSQL : DevExpress.XtraEditors.XtraForm
    {
        VNPT.Utility.Profile.Xml xml_ = new Utility.Profile.Xml();
        public fEditSQL()
        {
            InitializeComponent();
            this.Shown += (a, e) =>
            {
                using (new DevExpress.Utils.WaitDialogForm("Đang tải dữ liệu, xin vui lòng chờ trong giây lát..."))
                {
                    if (!string.IsNullOrWhiteSpace(_Key))
                    {
                        Type type = typeof(DoiSoatSetting);
                        mySQLEditor1.Text = type.GetProperties().ToList<PropertyInfo>().Where(p => p.Name == _Key).Any() ?
                        type.GetProperties().ToList<PropertyInfo>().Where(p => p.Name == _Key).First().GetValue(_Key, null).ToString() : "Sai khóa lấy!";
                        mySQLEditor1.Refresh();
                        labelControl1.Text = _GhiChu;
                        labelControl2.Text = _ThamSo;
                    }
                }
                
            };
        }
        string _Key;
        string _GhiChu;
        string _ThamSo;

        public fEditSQL(string Key, string GhiChu, string ThamSo):this()
        {
            _ThamSo = ThamSo;
            _Key = Key;
            _GhiChu = GhiChu;
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            //switch (_Key)
            //{
            //    case "SQL_GOI_DEN_CO_DINH_DLK":
            //        DoiSoatSetting.SQL_GOI_DEN_CO_DINH_DLK = mySQLEditor1.Text;
            //        break;
            //    case "SQL_GOI_DEN_GPHONE_DLK":
            //        DoiSoatSetting.SQL_GOI_DEN_GPHONE_DLK = mySQLEditor1.Text;
            //        break;
            //    case "SQL_GPHONE_DLK_GOI_DI":
            //        DoiSoatSetting.SQL_GPHONE_DLK_GOI_DI = mySQLEditor1.Text;
            //        break;
            //    case "SQL_CO_DINH_DLK_GOI_DI":
            //        DoiSoatSetting.SQL_CO_DINH_DLK_GOI_DI = mySQLEditor1.Text;
            //        break;
            //    default:
            //        xml_.SetValue("DOI_SOAT", _Key, mySQLEditor1.Text);
            //        break;
            //}

            Type type = typeof(DoiSoatSetting);
            var kt = type.GetProperties().ToList<PropertyInfo>().Where(p => p.Name == _Key);
            if (kt.Any())
            {
                type.GetProperties().ToList<PropertyInfo>().Where(p => p.Name == _Key).First().SetValue(_Key, mySQLEditor1.Text, null);
            }
            

            this.Close();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
          //  MessageBox.Show(mySQLEditor1.Text);
        }


    }
}
